package com.itheima.controller;

import com.itheima.common.PageResult2;
import com.itheima.entity.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/users")
public class UserController {
    @Autowired
    private UserService userService;

    //分页显示
    @GetMapping
    public PageResult2 findUserPage(Integer page,Integer pagesize,String username){
        return userService.findUserPage(page,pagesize,username);
    }

    //修改回显
    @GetMapping("{id}")
    public User findById(@PathVariable Integer id){
        return userService.findById(id);
    }

    //修改
    @PutMapping("{id}")
    public User updateUserById(@PathVariable Integer id,@RequestBody User user){
        return userService.updateUserById(id,user);
    }
    //新增
    @PostMapping
    public String add(@RequestBody User user){
        return userService.add(user);
    }
    //删除
    @DeleteMapping("{id}")
    public void deleteById(@PathVariable Integer id){
        userService.deleteById(id);
    }

    //屏蔽启用
    @PutMapping("{id}/disabled")
    public void updateState(@PathVariable Integer id, @RequestBody Map<String, String> map){
        userService.updateState(id,map);
    }

    //用户简单列表
    @GetMapping("simple")
    public List simple(){
        return userService.simple();
    }
    @PutMapping("{id}/password")
    public void updatePass(@PathVariable Integer id,@RequestBody Map<String, String> map){
         userService.updatePass(id,map);
    }
}
